<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/toggle.css" />
        <script src="js/jquery-3.3.1.min.js"></script>
         <script src="js/config.js"></script>
		<title>切换账户</title>
	</head>
	<body>
		
		<div class="page">
			
			<div class="top">
				
				<div>
					<h4>老用户登录</h4>
				</div>
			</div>
			
			
			<div class="content">
				
				<div class="tip">
					<span>不支持iOS账号和安卓账号互切</span>
				</div>
				
				<label for="phone">
					<div class="title">手机号</div>
					<input type="tel" id="phone" placeholder="输入手机号码" maxlength="13" class="input">					
				</label>
				<div class="division"></div>
				
				<div class="send-code">
					<button>获取验证码</button>
				</div>
				
				<div class="bottom-line"></div>
				
				
				<label for="code">
					
					<div class="title">验证码</div>
					<input type="tel" id="code" placeholder="输入验证码" class="input">
					<div class="bottom-line"></div>
				</label>
				
				
				<button class="submit">
					登录
				</button>
			</div>
			
			
		</div>
		<script type="text/javascript">
		var path = "/decorate";
		$(function () {
			
			$(".send-code").on("click",function(){
				var token = getCookie("deviceToken");
		    	$.ajax({
		    		url : path+"/dk/logout.do?deviceToken="+token,
		    		data:{},
		    		type : "get",
		    		success : function(res) {
		    			if(res.respCode == 0){
		    				var phone = document.getElementById('phone').value;
		    	             if(!(/^1[34578]\d{9}$/.test(phone))){
		    	                 toast("手机号码有误，请重填",500);
		    	                 return false;
		    	             }
		    				sendMsg(phone)
		    				var second = 60;
				            var set = setInterval(function(){
				                second--;
				                var html = second +"s";
				                $(".send-code button").html(html)
				                $(".send-code").css({backgroundColor:'#ccc'})
				
				                if(second <= 0){
				                    clearInterval(set);
				                    $(".send-code button").html("发送验证码")
				                    $(".send-code").css({backgroundColor:'#4A90E2'})
				                }
				
				            },1000)
		    			}
		    		},
		    		error : function() {
		    			console.log("error")
		    		}
		    	})	
			})
	    	
	    	 $(".submit").on("click",function(){
        	var phone = $("#phone").val();
        	var code = $("#code").val();
        	
        	var query = {
        			"channel":GetQueryString("channel"),
        			"mobile":phone,
        			"code":code,
        			"codeLogin":1,
        			"loginType":"login"
        		};
        	$.ajax({
        		url : path+"/dk/login.do",
        		data:query,
        		type : "get",
        		success : function(obj) {
        			if(obj.respCode == 0){
        				window.location.href="/task/views/app/index.html"
        			}
        		},
        		error : function() {
        			console.log("error")
        		}
        	})
        })
	    	
        function getCookie(name) {
		    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
		    if(arr=document.cookie.match(reg))
		        return unescape(arr[2]);
		    else
		        return null;
		}
			
			function GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r != null)
					return unescape(r[2]);
				return null;
			}
			
	    	function sendMsg(phone){
	        	var query = {
	        			"channel":GetQueryString("channel"),
	        			"mobile":phone,
	        			"loginType":"login"
	        		};
	        	$.ajax({
	        		url : path+"/dk/send/sms.do",
	        		data:query,
	        		type : "get",
	        		success : function(res) {
	        			if(res.respCode == 0){
	                         
	        			}
	        		},
	        		error : function() {
	        			console.log("error")
	        		}
	        	})
	        }
	    	
	    	
		})
		
		
		</script>
	</body>
</html>
